<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/js/base.js"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.2.7.6.js"></script>
</head>
<body>

<form class="layui-form" action=""  style="margin-top: 50px;" lay-filter="formFilter">
    <div class="layui-form-item">
        <label class="layui-form-label">登录名称</label>
        <div class="layui-input-inline">
            <input type="text" name="user_name" lay-verify="user_name" autocomplete="off" disabled placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="lay-form">立即提交</button>
        </div>
    </div>
</form>

<script>
    var userName = localStorage.getItem('hypercmfname')
    $("input[name=user_name]").val(userName)
    layui.use(['form', 'util', 'laydate'], function(){
        var form = layui.form;
        var layer =  parent.layui.layer;
        var laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //提交事件
        form.on('submit(lay-form)', function(data){

            $.ajax({
                url:'/admin/user/editPassword',
                data:data.field,
                async:false,
                type:'post',
                dataType:'json',
                headers:{
                    'token':localStorage.getItem('hypercmfname')+'_'+localStorage.getItem('token'),
                    'accept':'*/*'
                },
                success:function(res){
                    if(res.code==1){
                        layer.msg('操作成功',{
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        },function () {

                            localStorage.removeItem('token')
                            localStorage.removeItem('token_expire_time')
                            layer.closeAll()

                        })
                        alert('请使用新密码重新登录！')
                        localStorage.removeItem('token')
                        localStorage.removeItem('token_expire_time')
                        parent.window.location.href="/admin/login.html"

                    }else{
                        layer.alert(res.msg,{icon:5})//1√，2×，3问号，4锁，5不开心，6开心
                    }
                },fail:function(res){
                    layer.alert('请求失败',{icon:2})
                }
            })
        });


    });
</script>

</body>
</html>